<?php
/**
 * 	Table of Contents
 *
 *	- nice_theme_setup()
 *	- nice_custom_styling()
 *	- nice_custom_fonts()
 *	- nice_load_web_fonts()
 *	- nice_standard_fonts()
 *	- nice_theme_body_classes()
 *	- Nice_Walker
 *	- nice_upload_mimes()
 */

if ( ! function_exists( 'nice_theme_setup' ) ) {

	function nice_theme_setup() {

		// This tells the FW where to get updates from.
		define ( 'NICE_THEME_SLUG', 'paeon' );

		$hard_crop = get_option( 'nice_wp_resize_crop' );

		if ( $hard_crop == 'true' ) {
			$hard_crop = true;
		} else {
			$hard_crop = false;
		}

		add_image_size( 'nice-template-blog', 480, 480, $hard_crop );
		add_image_size( 'nice-slide', 2560, 1000, $hard_crop );
		add_image_size( 'nice-feedback', 200, 200, $hard_crop );
		add_image_size( 'nice-single-post', 730, 338, $hard_crop );
		add_image_size( 'nice-template-archive', 320, 200, $hard_crop );
		add_image_size( 'nice-template-masonry-blog', 580, 405, $hard_crop );
		add_image_size( 'nice-template-search', 620, 285, $hard_crop );
		add_image_size( 'nice-template-staff', 480, 468, $hard_crop );
		add_image_size( 'nice-template-contact', 480, 755, $hard_crop );
		add_image_size( 'nice-home-service', 480, 390, $hard_crop );
		add_image_size( 'nice-template-service-two', 480, 180, $hard_crop );

	}

}

add_action( 'after_setup_theme', 'nice_theme_setup' );

/**
 * nice_copyright_filter()
 *
 * Set the copyright arguments for this the function nice_copyright()
 *
 * @since 1.0.6
 *
 */

function nice_copyright_filter( $args ){

	global $nice_options;

	$text = '';

	$custom_copyright_enable = get_option( 'nice_custom_copyright_enable' );

	if ( isset( $custom_copyright_enable ) && ( $custom_copyright_enable == 'true' ) ) {

		$custom_copyright_text = get_option( 'nice_custom_copyright_text' );

		if ( isset( $custom_copyright_text ) && ( $custom_copyright_text <> '' ) ) {
			$text .= $custom_copyright_text;
		}

	} else {

		$text = '<a href="http://nicethemes.com/theme/paeon/" target="_blank" title="Paeon WordPress Theme">Paeon</a> ' . sprintf( __( 'by %s', 'nicethemes' ), '<a href="http://nicethemes.com" title="Wordpress Nice Themes">Nice Themes</a>' ) .' &copy; ' . date( 'Y' ) . ' &mdash; ' . sprintf( __( 'Powered by %s', 'nicethemes' ), '<a href="http://wordpress.org">WordPress</a>' ) . '.';

	}

	$args['text'] = $text;

	return $args;
}

add_filter( 'nice_copyright_default_args', 'nice_copyright_filter' );

/**
 * nice_logo_filter()
 *
 * Set the logo arguments for the function nice_logo.
 *
 * @since 1.0.6
 *
 */

 function nice_logo_filter( $args ){

	$nice_logo = get_option( 'nice_logo' );
	if ( isset( $nice_logo ) && $nice_logo <> '' )
		$args['logo'] = $nice_logo;

	$nice_logo_retina = get_option( 'nice_logo_retina' );
	if ( isset( $nice_logo_retina ) && $nice_logo_retina <> '' )
		$args['logo'] = $nice_logo_retina;

	$nice_text_title = get_option( 'nice_texttitle' );
	if ( isset( $nice_text_title ) && $nice_text_title == 'true' )
		$args['text_title'] = true;

	return $args;
}

add_filter( 'nice_logo_default_args', 'nice_logo_filter' );


/**
 * nicethemes_gallery_filter()
 *
 * Set the gallery arguments for the function nice_gallery
 *
 * @since 1.0.6
 *
 */

function nicethemes_gallery_filter( $args ){

	$args['columns'] = 5;

	return $args;
}
add_filter( 'nicethemes_gallery_default_args', 'nicethemes_gallery_filter' );

/*-----------------------------------------------------------------------------------*/
/* Add Custom Styling to HEAD */
/*-----------------------------------------------------------------------------------*/

add_action( 'wp_enqueue_scripts', 'nice_custom_styling', 8 );

if ( ! function_exists( 'nice_custom_styling' ) ) {

	function nice_custom_styling() {

		global $nice_options;

		$output = '';

		wp_enqueue_style( 'nice-options-styles', get_template_directory_uri() . '/includes/css/nice-options.css' );

		$nice_accent_color = get_option( 'nice_accent_color' );
		if ( isset( $nice_accent_color ) ) {

					$output .= '/* Nice Custom Styling */'. "\n\n";
					$output .= '#navigation .nav li:hover a, #navigation .nav li.current-menu-ancestor a, #navigation .nav li.current-menu-item a, #navigation .nav li.sfHover, .nav li ul, #top #navigation .nav li ul li a, ul.four-col-grid .thumb a, .nice-contact-form input[type=submit], input[type="submit"], #tabs .inside .tags a:hover, .flex-caption a.read-more, #header #top #toggle-nav{ background-color: ' . $nice_accent_color . ';  }' . "\n";
					$output .= '#filter li a:hover, #filter li.active a{ background: ' . $nice_accent_color . ';  }' . "\n";
					$output .= '#footer .testimonials .feedback .feedback-url, a, body #sidebar .widget_nice_appointments h3, .home-block h3, .welcome-message h2 b, .welcome-message h2 strong, .welcome-message h2 span, .one-col-grid.service-grid .entry-title a,.page-head h1.entry-title, body.page-template-template-contact-php #content h3, span.required, .home-staff li .staff-deparment a:hover, body.single-staff .staff-info header h1, .nice-contact-form #node{ color: ' . $nice_accent_color . ';  }' . "\n";
					$output .= '.entry blockquote{ border-left-color: ' . $nice_accent_color . ';  }' . "\n";
					$output .= '.flex-caption p a{ border-bottom-color: ' . $nice_accent_color . ';  }' . "\n";

		}

		$nice_secondary_color = get_option( 'nice_secondary_color' );
		if ( isset( $nice_secondary_color ) ) {
			$output .= '.call-number{ color: ' . $nice_secondary_color . ';  }' . "\n";
			$output .= '#commentform input[type="submit"], #footer-widgets .textwidget .read-more-link, #nice_appointment input[type="submit"], .button-bg{ background: ' . $nice_secondary_color . ';  }' . "\n";
		}

		$nice_header_background_color = get_option( 'nice_header_background_color' );
		if ( isset( $nice_header_background_color ) && $nice_header_background_color ) {
			$output .= '#header { background-color: ' . $nice_header_background_color. '; }' . "\n";
			$output .= '@media screen and (max-width: 1024px) { .has-slider #header { background-color: ' . $nice_header_background_color . '; } }' . "\n";
		}

		$nice_header_background_image = get_option( 'nice_header_background_image' );
		if ( isset( $nice_header_background_image ) && $nice_header_background_image ) {
			$output .= '#header { background-image : url(' . $nice_header_background_image . '); }' . "\n";
		}

		$nice_header_background_image_position = get_option( 'nice_header_background_image_position' );
		if ( isset( $nice_header_background_image_position ) && $nice_header_background_image_position ) {
			$output .= '#header { background-position : ' . $nice_header_background_image_position . '; }' . "\n";
		}

		$nice_header_background_image_repeat = get_option( 'nice_header_background_image_repeat' );
		if ( isset( $nice_header_background_image_repeat ) && $nice_header_background_image_repeat ) {
			$output .= '#header { background-repeat : ' . $nice_header_background_image_repeat . '; }' . "\n";
		}

		$nice_logo_height = get_option( 'nice_logo_height' );
		if ( isset( $nice_logo_height )  && $nice_logo_height != '' ) {
			$output .= '#default-logo, #retina-logo { height : ' . $nice_logo_height . 'px; }' . "\n";
		}

		if ( isset( $nice_options['nice_header_background_color'] ) && isset( $output ) && $output != '' ) {
			wp_add_inline_style( 'nice-options-styles', $output );
		}

	}
}


add_action( 'wp_enqueue_scripts', 'nice_custom_fonts', 20 );

/*
*/

if ( ! function_exists( 'nice_custom_fonts' ) ) {

	function nice_custom_fonts() {

		global $nice_options;

		$output = '';

		wp_enqueue_style( 'nice-options-styles', get_template_directory_uri() . '/includes/css/nice-options.css' );

		if ( isset( $nice_options['nice_custom_typography'] ) && ( nice_bool( $nice_options['nice_custom_typography'] ) ) ) {

			if ( isset( $nice_options['nice_font_body'] ) && $nice_options['nice_font_body'] )
				$output .= 'body { ' . nice_custom_font_css( $nice_options['nice_font_body'] ) . ' }' . "\n";

			if ( isset( $nice_options['nice_font_nav'] ) && $nice_options['nice_font_nav'] )
				$output .= '#header #navigation .nav li a, #navigation .nav li ul li a, #top #navigation .nav li ul li a {' . nice_custom_font_css( $nice_options['nice_font_nav'] ) . ' }' . "\n";

			if ( isset( $nice_options['nice_font_post_title'] ) && $nice_options['nice_font_post_title'] )
				$output .= '.post h2 { ' . nice_custom_font_css( $nice_options['nice_font_post_title'] ) . ' }' . "\n";

			if ( isset( $nice_options['nice_font_post_meta'] ) && $nice_options['nice_font_post_meta'] )
				$output .= '.post-meta { ' . nice_custom_font_css( $nice_options['nice_font_post_meta'] ) . ' }' . "\n";

			if ( isset( $nice_options['nice_font_post_entry'] ) && $nice_options['nice_font_post_entry'] )
				$output .= '.entry, .post-content { ' . nice_custom_font_css( $nice_options['nice_font_post_entry'] ) . ' }' . "\n";

			if ( isset( $nice_options['nice_font_welcome_message'] ) && $nice_options['nice_font_welcome_message'] )
				$output .= '.welcome-message h2 { ' . nice_custom_font_css( $nice_options['nice_font_welcome_message'] ) . ' }' . "\n";

			if ( isset( $nice_options['nice_font_welcome_message_extended'] ) && $nice_options['nice_font_welcome_message_extended'] )
				$output .= '.welcome-message p { ' . nice_custom_font_css( $nice_options['nice_font_welcome_message_extended'] ) . ' }' . "\n";

			if ( isset( $nice_options['nice_font_slider_title'] ) && $nice_options['nice_font_slider_title'] )
				$output .= '.flexslider .slides li h2 {' . nice_custom_font_css( $nice_options['nice_font_slider_title'] ) . ' }' . "\n";

			if ( isset( $nice_options['nice_font_slider_content'] ) && $nice_options['nice_font_slider_content'] )
				$output .= '.flex-caption p { ' . nice_custom_font_css( $nice_options['nice_font_slider_content'] ) . ' }' . "\n";

		}

		// Add Text title and tagline if text title option is enabled
		if ( isset( $nice_options['nice_texttitle'] ) && ( nice_bool( $nice_options['nice_texttitle'] ) ) ) {

			if ( $nice_options['nice_font_site_title'] ){

				$output .= '#header #top #logo a .text-logo { ' . nice_custom_font_css( $nice_options['nice_font_site_title'] ) . ' }' . "\n";

			}
		}

		if ( isset( $output ) && $output != '' ) {
			$output = strip_tags( '/* Nice Custom Fonts */' . "\n\n" . $output );
			wp_add_inline_style( 'nice-options-styles', $output );
		}

	}

} // endif;


add_action( 'wp_head', 'nice_load_web_fonts', 15 );

if ( ! function_exists( 'nice_load_web_fonts' ) ) {

	function nice_load_web_fonts() {

		global $google_fonts;
		$fonts = '';
		$html = '';

		global $nice_options;

		// Go through the options
		if ( ! empty( $nice_options ) &&
				(
					( isset( $nice_options['nice_texttitle'] ) && ( nice_bool( $nice_options['nice_texttitle'] ) ) ) ||
					( isset( $nice_options['nice_custom_typography'] ) && ( nice_bool( $nice_options['nice_custom_typography'] ) ) )
				)
			) {

			foreach ( $nice_options as $option ) :

				if ( is_array( $option ) && isset( $option['family'] ) ) {

					foreach ( $google_fonts as $font ) :

						if ( ( $option['family'] == $font['name'] ) && ( ! strstr( $fonts, $font['name'] ) ) ) {

							$fonts .= $font['name'] . $font['variant'] . "|";

						}

					endforeach;
				}

			endforeach;

			// Output google font css in header
			if ( $fonts ) {

				$fonts = str_replace( " ", "+", $fonts );
				$html .= "\n\n<!-- Nice Google fonts -->\n";
				$html .= '<link href="http' . ( is_ssl() ? 's' : '' ) . '://fonts.googleapis.com/css?family=' . $fonts . '" rel="stylesheet" type="text/css" />' . "\n";
				$html = str_replace( '|"', '"', $html);

				echo $html . "\n\n";

			} if ( ( ! nice_bool( $nice_options['nice_custom_typography'] ) ) ){

					nice_standard_fonts();

			}

		} else {
				// fix for updated themes where no typography options were saved
				nice_standard_fonts();

		}

	} // End nice_load_web_fonts()

}

if ( ! function_exists( 'nice_standard_fonts' ) ) {

	function nice_standard_fonts() { ?>
		<link href='http<?php if ( is_ssl() ) echo 's'; ?>://fonts.googleapis.com/css?family=Open+Sans:700' rel='stylesheet' type='text/css'>
		<link href='http<?php if ( is_ssl() ) echo 's'; ?>://fonts.googleapis.com/css?family=Raleway:200,400,500,600,700,800' rel='stylesheet' type='text/css'>
	<?php
	}

}

/**
 * nice_theme_body_classes()
 *
 * set bodyclass for the sidebar alignment.
 *
 * @since 1.0.1
 *
 */
add_filter( 'body_class', 'nice_theme_body_classes' );

if ( ! function_exists( 'nice_theme_body_classes' ) ) {

	function nice_theme_body_classes( $classes ) {

		global $nice_options;

		if ( (is_home() || is_page_template( 'template-home.php' )) && nice_bool( $nice_options['nice_slider'] )  ) {

			$has_slides = get_posts( array ( 'post_type' => 'slide', 'showposts' => 1 ) );

			if ( ! empty ( $has_slides ) ) :

				$classes[] = 'has-slider has-slider-menu';

			endif;

		}

		return $classes;

	}

}


class Nice_Walker extends Walker_Category {

function start_el( &$output, $category, $depth = 0 , $args = array(), $current_category = 0 ) {

	extract( $args );
	$cat_name = esc_attr( $category->name );
	$cat_name = apply_filters( 'list_cats', $cat_name, $category );
		$link = '<a href="#" data-value="term-' . $category->term_id . '" ';
	if ( $use_desc_for_title == 0 || empty( $category->description ) )
		$link .= 'title="' . sprintf( __( 'View all items filed under %s', 'nicethemes' ), $cat_name ) . '"';
	else
		$link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
	$link .= '>';
	// $link .= $cat_name . '</a>';
	$link .= $cat_name;
	if ( ! empty( $category->description ) ) {
		$link .= ' <span>' . $category->description . '</span>';
	}
	$link .= '</a><span class="border"></span><span class="sep"></span>';
	if ( ( ! empty( $feed_image ) ) || ( ! empty( $feed )) ) {
		$link .= ' ';
		if ( empty( $feed_image ) )
			$link .= '(';
		$link .= '<a href="' . get_category_feed_link( $category->term_id, $feed_type ) . '"';
		if ( empty( $feed ) )
			$alt = ' alt="' . sprintf( __( 'Feed for all posts filed under %s', 'nicethemes' ), $cat_name ) . '"';
		else {
			$title = ' title="' . $feed . '"';
			$alt = ' alt="' . $feed . '"';
			$name = $feed;
			$link .= $title;
		}
		$link .= '>';
		if ( empty( $feed_image) )
			$link .= $name;
		else
			$link .= "<img src='$feed_image'$alt$title" . ' />';
		$link .= '</a>';
		if ( empty( $feed_image) )
			$link .= ')';
		}
		if ( isset( $show_count ) && $show_count )
			$link .= ' (' . intval( $category->count ) . ')';
		if ( isset( $show_date) && $show_date ) {
			$link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp );
		}
		if ( isset( $current_category) && $current_category )
			$_current_category = get_category( $current_category );
		if ( 'list' == $args['style'] ) {
			$output .= '<li class=" ';
			$class = 'segment-' . $category->term_id. ' cat-item cat-item-' . $category->term_id;
			if ( isset( $current_category) && $current_category && ( $category->term_id == $current_category ) )
				$class .=  ' current-cat';
			elseif ( isset( $_current_category) && $_current_category && ( $category->term_id == $_current_category->parent ) )
				$class .=  ' current-cat-parent';
			$output .=  $class . '"';
			$output .= ">$link\n";
		} else {
			$output .= "\t$link<br />\n";
		}
	}
}

/**
 * nice_back_to_top()
 *
 * Adds the code for the back to top button (if enabled through options)
 *
 * @since 1.0.0
 *
 */

if ( ! function_exists( 'nice_back_to_top' ) ) {

	function nice_back_to_top() {

		global $nice_options;

		if ( isset( $nice_options['nice_back_to_top'] ) && $nice_options['nice_back_to_top'] == 'true' ): ?>
			<a href="#" class="backtotop">
				<i class="fa fa-chevron-up"></i>
			</a>
		<?php endif;

		return true;
	}

}

add_action( 'wp_footer', 'nice_back_to_top' );

?>